﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>管理员工</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <style type="text/css">
        .people_column
        {
            float: left;
            width: 50%;
            height: 80px;
            margin-top: 5px;
            margin-bottom: 5px;
        }
        .contact
        {
            clear: left;
            font-size: 14px;
            margin: 0 0 15px;
            min-height: 70px;
        }
        .avatar
        {
            float: left;
            width: 48px;
            height: 48px;
        }
        .badge p
        {
            font-size: 9px;
            font-weight: bold;
            text-transform: uppercase;
            margin-left: 2px;
            text-align: center;
        }
        .hr
        {
            background-color: #008000;
            font-size: 16px;
            color: #fff;
        }
        .employ
        {
            background-color: #CC9900;
            color: #fff;
            margin-top: 50px;
        }
        .body
        {
            margin-left: 56px;
        }
        
        a.admin
        {
            color: #ff0000;
        }
        
        a.admin:hover
        {
            background: none repeat scroll 0 0 #ff0000;
            color: #fff;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <script type="text/javascript">
    //************* URL常量

    var URL_APPLY_LEAVE = '/attendance/DoApplyLeave';

    //************* 全局变量

    var g_Var = {


};

//************* 常量定义


//************* Accessor访问器
var EzAccessor = {};

function CreateAccessor() {
    if (ezmock.IS_MOCKED) {
        EzAccessor = CreateMockEzAccessor();

    } else {
        EzAccessor = CreateRealEzAccessor();
    }
}


function CreateMockEzAccessor() {
    //模拟实现服务器交互方法

    var mockEzAccessor = {

};

return mockEzAccessor;
}

function CreateRealEzAccessor() {
    //实现服务器交互方法
    var realEzAccessor = {
        "getStaffList": function () {
            return <%= ViewData["StaffList"]%>;
        },"getUserId": function () {
            return <%= ViewData["UserId"]%>;
        }

    };

return realEzAccessor;
}


//绑定staffList
function bindStaffList(staffList){
    for(var key  in staffList){
       var  peopleCulumnDom = $(' <div class="people_column"></div>');
       var  avatarDom = $('<div class="avatar"></div>');
       var  bodyDom = $('<div class="body"></div>');

       var  staffInfoStr = '<div id="staffInfo_{userId}" class="contact"></div>'
       staffInfoStr = staffInfoStr.replace("{userId}", staffList[key].TargetUser.Id);
       //头像
       var imgaStr =  '<div>' + 
                        '<img class="avatar photo" height="48" width="48" src="/core/headicon/{userId}"alt=""/>' + 
                      '</div>';
       imgaStr = imgaStr.replace("{userId}",  staffList[key].TargetUser.Id);
       //角色信息
       var badgeStr = '<div class="badge">' + 
                         '<p class="employ">普通</p>' + 
                      '</div>';
       //基本信息
       var baseInfoStr = '<p>' + 
                             '<span class="name">{name}</span><span class="dept">({deptName})</span>' + 
                        '</p>' + 
                        '<p> ' + 
                            '<span class="moblie">{mobileNo}</span>' + 
                        '</p>';
       //处理电话号码为空
       var mobileNo = "";
       if(staffList[key].ContactInfo.MobileNo != null){
           mobileNo = staffList[key].ContactInfo.MobileNo;        
       }
       
       baseInfoStr = baseInfoStr.replace("{name}", staffList[key].TargetUser.Name)
                                .replace("{deptName}", staffList[key].TargetUser.Dept.DeptName)
                                .replace("{mobileNo}", mobileNo);
                                
       //编辑链接
       var editStr =  '<div class="edit">' +
                            '<a class="admin" onclick="edit(\'{userId}\')">编辑</a>' + 
                      '</div>';
       editStr = editStr.replace("{userId}", staffList[key].TargetUser.Id)

       avatarDom.append($(imgaStr))
                .append($(badgeStr));
       bodyDom.append($(baseInfoStr))
              .append($(editStr));
       $(staffInfoStr).append(avatarDom)
                      .append(bodyDom)
                      .appendTo(peopleCulumnDom);
        
       peopleCulumnDom.appendTo($('#divStaffList'))  
                        
    }
}

//编辑修改staff
function edit(userId){
    window.location.href = "/staff/EditStaff?userId=" +userId;

}

function highLightTargetUser(userId){
    //todo:锚点
    //window.location.href = '/Staff/Staff?UserId=' + userId  + '#staffInfo_' + userId;
    $('#staffInfo_' + userId).css({
            'background-color':'#FFEC8B',
            'border': '1px solid #ed4753'
    }); 

}

//初始化页面
function initPage() {
    CreateAccessor();
    var staffList = EzAccessor.getStaffList();
    var useId = EzAccessor.getUserId();
    bindStaffList(staffList);
    if(useId != null){
        highLightTargetUser(useId);
    }
   
}

//初始化事件
function initPageEvent() {


}

$(function () {
    initPage();
    initPageEvent();


});

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head" class="page-head"> 
        <img src="../../Content/icons/Sleek_XP_047.png" style="width: 48px; height: 48px;"
            alt="send" />
        <span class="title">管理员工</span>
    </div>
    <div id="page-body">
        <h3 style="background: none repeat scroll 0 0 #E9E9E9;">
            <span>您的公司名称：</span> <span id="cmbCompanyName">魏玛</span>
        </h3>
        <div id="divStaffList" style="overflow: hidden; margin-top: 10px;">
        </div>
    </div>
    <div class="page-submit">
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">
    <div id="shortcuts" class="box">
        <a id="btn-add-new-staff" href="/staff/addUser">添加新员工</a>
        <script>
            $(function () {
                $('#btn-add-new-staff').button({
                    icons: {
                        primary: 'ui-icon-circle-plus'
                    },
                    text: true
                });
            });
        </script>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <div id="tip_alert" style="display: none;">
</asp:Content>
